<?php
namespace addons\csmtable;

use think\Addons;
use think\Request;
use app\admin\library\Auth;
use app\common\library\Menu;
use addons\csmtable\library\CsmUtils;
use fast\Random;
use GuzzleHttp\Handler\CurlMultiHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Client;
use Psr\Http\Message\ResponseInterface;

/**
 * 插件
 */
class Csmtable extends Addons
{

    /**
     * 插件安装方法
     *
     * @return bool
     */
    public function install()
    {
        $menu = [
            [
                'name' => 'csmtable',
                'title' => 'Table功能增强',
                'sublist' => [
                    [
                        'name' => 'csmtable/test',
                        'title' => '使用示例',
                        'icon' => 'fa fa-meetup',
                        'sublist' => [
                            [
                                'name' => 'csmtable/test/index',
                                'title' => '查询'
                            ],
                            [
                                'name' => 'csmtable/test/recyclebin',
                                'title' => '回收站'
                            ],
                            [
                                'name' => 'csmtable/test/add',
                                'title' => '添加'
                            ],
                            [
                                'name' => 'csmtable/test/edit',
                                'title' => '修改'
                            ],
                            [
                                'name' => 'csmtable/test/del',
                                'title' => '删除'
                            ],
                            [
                                'name' => 'csmtable/test/destroy',
                                'title' => '真实删除'
                            ],
                            [
                                'name' => 'csmtable/test/restore',
                                'title' => '还原'
                            ],
                            [
                                'name' => 'csmtable/test/multi',
                                'title' => '批量更新'
                            ],
                            [
                                'name' => 'csmtable/test/import',
                                'title' => '导入'
                            ]
                        ]
                    ],
                    [
                        'name' => 'csmtable/xlstask',
                        'title' => '下载任务',
                        'icon' => 'fa fa-meetup',
                        'sublist' => [
                            [
                                'name' => 'csmtable/xlstask/index',
                                'title' => '查询'
                            ],
                            [
                                'name' => 'csmtable/xlstask/add',
                                'title' => '添加'
                            ],
                            [
                                'name' => 'csmtable/xlstask/edit',
                                'title' => '修改'
                            ],
                            [
                                'name' => 'csmtable/xlstask/del',
                                'title' => '删除'
                            ],
                            [
                                'name' => 'csmtable/csmgeneratesub/index',
                                'title' => '重新执行'
                            ],
                        ]
                    ]
                ]
            ]
        ];
        Menu::create($menu);
        return true;
    }

    /**
     * 插件卸载方法
     *
     * @return bool
     */
    public function uninstall()
    {
        Menu::delete("csmtable");
        return true;
    }

    /**
     * 插件启用方法
     *
     * @return bool
     */
    public function enable()
    {
        Menu::enable("csmtable");
        return true;
    }

    /**
     * 插件禁用方法
     *
     * @return bool
     */
    public function disable()
    {
        Menu::disable("csmtable");
        return true;
    }

    public function actionBegin($call)
    {
        $request = Request::instance();

        if (true) {
            // 判断是否安装了插件:表格无刷新行内编辑
            $path = $request->path();
            if ($path == 'csmtable/test') {
                $editable = get_addon_info('editable');
                if (! $editable || ! $editable['state']) {
                    CsmUtils::error("为更好的演示本功能，请安装【表格无刷新行内编辑】插件", null, null, 60);
                }
            }
        }
 
    }
 
}
